package com.cheney.demo.listener;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Service;

/**
 * @author si.chen
 * @date 2021/7/8 19:54
 */
@Service
public class ConsumerListener {

    /**
     * 消费者-使用日志打印消息
     */
    @KafkaListener(topics = "my-topic")
    public void receive(ConsumerRecord<?, ?> consumer) {
        System.out.println("topic名称:" + consumer.topic() + ",key:" + consumer.key() + ",value:" + consumer.value() + ",分区位置:" + consumer.partition()
                + ", 偏移量" + consumer.offset());
    }

    /**
     * 消费者-字符串消息
     */
    @StreamListener("input")
    public void receiveInput(String receiveMsg) {
        System.out.println("input receive: " + receiveMsg);
    }

    @StreamListener("input2")
    public void receiveInput2(String receiveMsg) {
        System.out.println("input2 receive: " + receiveMsg);
    }

    /*@StreamListener("input2")
    public void receiveInput2(@Payload Order order) {
        System.out.println("input2 receive: " + order);
    }

    @StreamListener("input3")
    public void receiveInput3(Message msg) {
        System.out.println("input3 receive: " + msg);
    }*/
}
